package com.tianqu.tms.core.webservice;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.List;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.exception.TmsDaoException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.util.DateUtil;
import com.tianqu.tms.core.util.ImageUtils;
import com.tianqu.tms.core.util.Registry;
import com.tianqu.tms.core.util.StringUtil;
import com.tianqu.tms.core.util.TmsConstants;
import com.tianqu.tms.core.webservice.weichat.api.MobileMessage;
import com.tianqu.tms.core.webservice.weichat.api.PullingExecutor;
import com.tianqu.tms.core.webservice.weichat.api.rpc.AddCarBo;
import com.tianqu.tms.core.webservice.weichat.api.rpc.TransferDataSyn0000Bo;
import com.tianqu.tms.dao.TmsDao;
import com.tianqu.tms.dao.TransferAcceptedInfoDaoImp;
import com.tianqu.tms.dao.TransferFinanceInfoDaoImp;
import com.tianqu.tms.dao.TransferProcessHistoryDaoImp;
import com.tianqu.tms.dto.TransferAcceptedInfoDto;
import com.tianqu.tms.dto.TransferProcessHistoryDto;
import com.tianqu.tms.entity.Car;
import com.tianqu.tms.entity.Member;
import com.tianqu.tms.entity.PicChangeHistory;
import com.tianqu.tms.entity.Sequence;
import com.tianqu.tms.entity.TransferAcceptedInfo;
import com.tianqu.tms.entity.TransferFinanceInfo;
import com.tianqu.tms.entity.TransferPersonalCarInfo;
import com.tianqu.tms.entity.TransferProcessHistory;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class TmsXmlResolveDataBaseTransUtil {
	private static Logger logger = Logger .getLogger(TmsXmlResolveDataBaseTransUtil.class);// log

	/**
	 * 用户、权限数据同步服务器端
	 * 
	 * @return
	 */
	public static String user() {
		logger.info("用户信息获取开始...");

		logger.info("用户信息获取结束...");
		return "";

	}
	/**
	 * pad 库存管理
	 * @param car
	 * @return
	 * @throws TmsDaoException 
	 */
	public static String checkMarketCar(Car car) throws TmsDaoException{
		
		
		
		String flags = "1";
		TxController controller = TxController.getTxController();
		
		Car carPad = Car.getInstance();
		carPad.setPhoto_1(car.getPhoto_1());
		carPad.setPhoto_2(car.getPhoto_2());
		carPad.setPhoto_3(car.getPhoto_3());
		carPad.setPhoto_4(car.getPhoto_4());
		carPad.setPhoto_5(car.getPhoto_5());
		carPad.setPhoto_6(car.getPhoto_6());
		carPad.setPhoto_7(car.getPhoto_7());
		carPad.setPhoto_8(car.getPhoto_8());
		try {
			controller.begin();
			Car newCar = Car.getInstance();//判断是否
			TransferAcceptedInfo accept1 = new TransferAcceptedInfo();//如果是非库存且没有过户完了，存在这一的车的话，返回失败。
			accept1 = accept1.findCarByLicense(car.getLicensePlate());
			if(accept1 != null){
				if(!StringUtil.isNullOrBlank(accept1.getSerial())){
					PicChangeHistory picChangeHistory = new PicChangeHistory();
					picChangeHistory.setLicensePlate(car.getLicensePlate());
					picChangeHistory.setInsertUserId(car.getInsertUserId());
					picChangeHistory.setOperateFlag(1);
					picChangeHistory.setRemark("车辆已经查验照相，不能进行入库。");
					picChangeHistory.setSuccessFlag(2);
					picChangeHistory.insertPicChange(picChangeHistory);
					return "2";
				}
			}
			//根据车牌号码查询车辆是否存在
			newCar = newCar.findCarForPad(car.getLicensePlate());
			
			if(StringUtil.isNullOrBlank(newCar.getSerial())){//如果不存在，插入数据，（库存表，进出库记录表，过户表，财务表，历史表）
				Sequence seq = Sequence.getInstance();
				String serial = seq.getSerial(1);
				// 处理四张图片
				if (carPad.getPhoto_1() != null&& !"".equals(carPad.getPhoto_1())) {
					String patch1 = imageTool(serial, "1",carPad.getPhoto_1(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_1(patch1);
				} else {
					logger.info("库存图片1为空!");
					car.setPhoto_1("");
				}
				if (carPad.getPhoto_2() != null&& !"".equals(carPad.getPhoto_2())) {
					String patch2 = imageTool(serial, "2",carPad.getPhoto_2(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_2(patch2);
				} else {
					logger.info("库存图片2为空!");
					car.setPhoto_2("");
				}
				if (carPad.getPhoto_3() != null&& !"".equals(carPad.getPhoto_3())) {
					String patch3 = imageTool(serial, "3",carPad.getPhoto_3(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_3(patch3);
				} else {
					logger.info("库存图片3为空!");
					car.setPhoto_3("");
				}
				if (carPad.getPhoto_4() != null&& !"".equals(carPad.getPhoto_4())) {
					String patch4 = imageTool(serial, "4",carPad.getPhoto_4(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_4(patch4);
				} else {
					logger.info("库存图片4为空!");
					car.setPhoto_4("");
				}
				if (carPad.getPhoto_5() != null&& !"".equals(carPad.getPhoto_5())) {
					String patch5 = imageTool(serial, "5",carPad.getPhoto_5(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_5(patch5);
				} else {
					logger.info("库存图片5为空!");
					car.setPhoto_5("");
				}
				if (carPad.getPhoto_6() != null&& !"".equals(carPad.getPhoto_6())) {
					String patch6 = imageTool(serial, "6",carPad.getPhoto_6(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_6(patch6);
				} else {
					logger.info("库存图片6为空!");
					car.setPhoto_6("");
				}
				if (carPad.getPhoto_7() != null&& !"".equals(carPad.getPhoto_7())) {
					String patch7 = imageTool(serial, "7",carPad.getPhoto_7(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_7(patch7);
				} else {
					logger.info("库存图片7为空!");
					car.setPhoto_7("");
				}
				if (carPad.getPhoto_8() != null&& !"".equals(carPad.getPhoto_8())) {
					String patch8 = imageTool(serial, "8",carPad.getPhoto_8(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
					car.setPhoto_8(patch8);
				} else {
					logger.info("库存图片8为空!");
					car.setPhoto_8("");
				}
				    car.setAttestStatus(1);
				    car.setStatus(1);
				    car.setEntryStatus(1);
				    //modify by huangheli at 20150811 start
				    //car.setRegisterStatus(1);
				    car.setRegisterStatus(6);
				    //modify by huangheli at 20150811 end
				    car.setSerial(serial);
				    car.insertCarInfo(car);//插入库存
					String transferSerial = seq.getSerial(6);
					
					//modify by huangheli at 20150811 start
					MobileMessage message = new MobileMessage();
					message.putValue("Serial", serial);
					message.putValue("LicensePlate", car.getLicensePlate());
					message.setMessage("TMS PAD无法同步[添加车辆]接口,serial为#Serial#,车牌号为#LicensePlate#");
					
					AddCarBo bo = new AddCarBo();
					bo.setMobileMessage(message);
					bo.setSerial(serial);
					bo.setTransferSerial(transferSerial);
					bo.setLicensePlate(car.getLicensePlate());
					bo.setMileage(car.getMileage());
					bo.setVendorId(car.getVendorId());
					bo.setBrandId(car.getBrandId());
					bo.setCarStyleId(car.getCarStyleId());
					bo.setColor(car.getColor());
					bo.setPrice(car.getPrice());
					bo.setMemberId(String.valueOf(car.getMemberId()));
					PullingExecutor.getInstance().submit(bo);
					
//					//库存车辆进场库记录信息插入
//					MarketCarGateInfo marketCarGateInfo = MarketCarGateInfo.getInstance();
//					marketCarGateInfo.setSerial(serial);
//					marketCarGateInfo.setCarScore(7);
//					marketCarGateInfo.setInoutMark(1);//入库
//					marketCarGateInfo.insertGateInfo(marketCarGateInfo);
					//modify by huangheli at 20150811 end
					
					TransferAcceptedInfo accept = new TransferAcceptedInfo();
					accept.setSerial(transferSerial);
					
					// 处理四长图片
					if (carPad.getPhoto_1() != null&& !"".equals(carPad.getPhoto_1())) {
						String patch1 = imageTool(accept.getSerial(), "1",carPad.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_1(patch1);
					} else {
						logger.info("图片1为空!");
						accept.setPhoto_1("");
					}
					if (carPad.getPhoto_2() != null&& !"".equals(carPad.getPhoto_2())) {
						String patch2 = imageTool(accept.getSerial(), "2",carPad.getPhoto_2(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_2(patch2);
					} else {
						logger.info("图片2为空!");
						accept.setPhoto_2("");
					}
					if (carPad.getPhoto_3() != null&& !"".equals(carPad.getPhoto_3())) {
						String patch3 = imageTool(accept.getSerial(), "3",carPad.getPhoto_3(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_3(patch3);
					} else {
						logger.info("图片3为空!");
						accept.setPhoto_3("");
					}
					if (carPad.getPhoto_4() != null&& !"".equals(carPad.getPhoto_4())) {
						String patch4 = imageTool(accept.getSerial(), "4",carPad.getPhoto_4(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_4(patch4);
					} else {
						logger.info("图片4为空!");
						accept.setPhoto_4("");
					}
					accept.setLicensePlate(car.getLicensePlate());
					accept.setInsertUserid(car.getInsertUserId());
					accept.setUpdateUserId(car.getInsertUserId());
					accept.setBasicCarId(serial);
					// add by huangheli at 20150919 start
					accept.setMemberId(String.valueOf(car.getMemberId()));
					// add by huangheli at 20150919 end
					accept.insertEasyCar(accept);//插入过户表
					
					PicChangeHistory picChangeHistory = new PicChangeHistory();
					picChangeHistory.setLicensePlate(car.getLicensePlate());
					picChangeHistory.setInsertUserId(car.getInsertUserId());
					picChangeHistory.setOperateFlag(1);
					picChangeHistory.setRemark("车辆为库存车辆，插入成功.");
					picChangeHistory.setSuccessFlag(1);
					picChangeHistory.insertPicChange(picChangeHistory);
					
					//过户流程操作记录表
					TransferProcessHistory transferProcessHistory = new TransferProcessHistory();
					transferProcessHistory.setSerial(transferSerial);
					transferProcessHistory.setBusinessType(0);
					transferProcessHistory.setInsertUserId(car.getInsertUserId());
					transferProcessHistory.insertHisInfoAtAssess(transferProcessHistory);
					
					//过户业务的财务收费信息表
					TransferFinanceInfo transferFinanceInfo = new TransferFinanceInfo();
					transferFinanceInfo.insertFinanceByInner(transferSerial);
									   
			}else{
				//delete by huangheli 20150908 start
//				TransferAcceptedInfo accept = new TransferAcceptedInfo();
//				
//				accept = accept.findTransferByBasicCarId(newCar.getSerial());
				
				
//				if(accept.getCheckUserid() == 0 || accept.getStatus()==18){

//				//判断图片，如果数据库中的图片为空的话，就更新
//				
//				if (carPad.getPhoto_1() != null&& !"".equals(carPad.getPhoto_1())) {
//					String patch1 = imageTool(newCar.getSerial(), "1",carPad.getPhoto_1(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_1(patch1);
//				} else {
//					newCar.setPhoto_1(newCar.getPhoto_1());
//					logger.info("库存图片1为空!");
//				}
//			
//
//				if (carPad.getPhoto_2() != null&& !"".equals(carPad.getPhoto_2())) {
//					String patch2 = imageTool(newCar.getSerial(), "2",carPad.getPhoto_2(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_2(patch2);
//				} else {
//					newCar.setPhoto_2(newCar.getPhoto_2());
//					logger.info("库存图片2为空!");
//				}
//
//				if (carPad.getPhoto_3() != null&& !"".equals(carPad.getPhoto_3())) {
//					String patch3 = imageTool(newCar.getSerial(), "3",carPad.getPhoto_3(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_3(patch3);
//				} else {
//					newCar.setPhoto_3(newCar.getPhoto_3());
//					logger.info("库存图片3为空!");
//				}
//
//				if (carPad.getPhoto_4() != null&& !"".equals(carPad.getPhoto_4())) {
//					String patch4 = imageTool(newCar.getSerial(), "4",carPad.getPhoto_4(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_4(patch4);
//				} else {
//					newCar.setPhoto_4(newCar.getPhoto_4());
//					logger.info("库存图片4为空!");
//				}
//
//				if (carPad.getPhoto_5() != null&& !"".equals(carPad.getPhoto_5())) {
//					String patch5 = imageTool(newCar.getSerial(), "5",carPad.getPhoto_5(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_5(patch5);
//				} else {
//					newCar.setPhoto_5(newCar.getPhoto_5());
//					logger.info("库存图片5为空!");
//				}
//
//				if (carPad.getPhoto_6() != null&& !"".equals(carPad.getPhoto_6())) {
//					String patch6 = imageTool(newCar.getSerial(), "6",carPad.getPhoto_6(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_6(patch6);
//				} else {
//					newCar.setPhoto_6(newCar.getPhoto_6());
//					logger.info("库存图片6为空!");
//				}
//
//				if (carPad.getPhoto_7() != null&& !"".equals(carPad.getPhoto_7())) {
//					String patch7 = imageTool(newCar.getSerial(), "7",carPad.getPhoto_7(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_7(patch7);
//				} else {
//					newCar.setPhoto_7(newCar.getPhoto_7());
//					logger.info("库存图片7为空!");
//				}
//
//				if (carPad.getPhoto_8() != null&& !"".equals(carPad.getPhoto_8())) {
//					String patch8 = imageTool(newCar.getSerial(), "8",carPad.getPhoto_8(),TmsConstants.WEB_SERVICE_PIC,TmsConstants.UPLOAD_CONTEXT_ROOT);
//					newCar.setPhoto_8(patch8);
//				} else {
//					newCar.setPhoto_8(newCar.getPhoto_8());
//					logger.info("库存图片8为空!");
//				}
//				
//				//会员ID ，行驶里程，价格
//				if(car.getMemberId() != 0){
//					newCar.setMemberId(car.getMemberId());
//				}
//				if(car.getMileage() != 0){
//					newCar.setMileage(car.getMileage());
//				}
//				if(car.getPrice() != 0){
//					newCar.setPrice(car.getPrice());
//				}
//				newCar.updateCarAtPad(newCar);
				
				
				
//					// 处理四长图片
//					if (carPad.getPhoto_1() != null&& !"".equals(carPad.getPhoto_1())) {
//						String patch1 = imageTool(accept.getSerial(), "1",carPad.getPhoto_1(),TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD,TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT);
//						accept.setPhoto_1(patch1);
//					} else {					
//						logger.info("图片1为空!");				
//					}
//					if (carPad.getPhoto_2() != null&& !"".equals(carPad.getPhoto_2())) {
//						String patch2 = imageTool(accept.getSerial(), "2",carPad.getPhoto_2(),TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD,TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT);
//						accept.setPhoto_2(patch2);
//					} else {
//						logger.info("图片2为空!");				
//					}
//					if (carPad.getPhoto_3() != null&& !"".equals(carPad.getPhoto_3())) {
//						String patch3 = imageTool(accept.getSerial(), "3",carPad.getPhoto_3(),TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD,TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT);
//						accept.setPhoto_3(patch3);
//					} else {
//						logger.info("图片3为空!");					
//					}
//					if (carPad.getPhoto_4() != null&& !"".equals(carPad.getPhoto_4())) {
//						String patch4 = imageTool(accept.getSerial(), "4",carPad.getPhoto_4(),TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD,TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT);
//						accept.setPhoto_4(patch4);
//					} else {
//						logger.info("图片4为空!");				
//					}
//					accept.setUpdateUserId(car.getUpdateUserId());
//					accept.setPicChangeNum(accept.getPicChangeNum() + 1);
//					accept.setPicChangeUserId(car.getUpdateUserId());
//					accept.updatePadMarket(accept);
//					PicChangeHistory picChangeHistory = new PicChangeHistory();
//					picChangeHistory.setLicensePlate(car.getLicensePlate());
//					picChangeHistory.setInsertUserId(car.getInsertUserId());
//					picChangeHistory.setOperateFlag(2);
//					picChangeHistory.setRemark("车辆为库存车辆，更新成功.");
//					picChangeHistory.setSuccessFlag(1);
//					picChangeHistory.insertPicChange(picChangeHistory);
//				}else{
				//delete by huangheli 20150908 end
					PicChangeHistory picChangeHistory = new PicChangeHistory();
					picChangeHistory.setLicensePlate(car.getLicensePlate());
					picChangeHistory.setInsertUserId(car.getInsertUserId());
					picChangeHistory.setOperateFlag(2);
					//picChangeHistory.setRemark("车辆为库存车辆，但处于过户中，更新失败.");
					picChangeHistory.setRemark("车辆为已经入库，更新失败.");
					picChangeHistory.setSuccessFlag(2);
					picChangeHistory.insertPicChange(picChangeHistory);
					flags = "2";
//				}
				
			}
			controller.commit();
			}catch (TransactionException e) {
				try {
					controller.rollback();
				} catch (TransactionException e1) {
					// TODO Auto-generated catch block 
					e1.printStackTrace();
				}
				e.printStackTrace();
			}
		return flags;
	}
	/**
	 * @param accept
	 * @throws TmsDaoException
	 *             * 照片查验
	 */
	public static   String checkImg(TransferAcceptedInfo accept)
			throws TmsDaoException {
		
		String flags = "1";
		TxController controller = TxController.getTxController();
		try {
			controller.begin();
			
			
			if (("".equals(accept.getLicensePlate()) || accept.getLicensePlate() == null)&& (!"".equals(accept.getVin()) && accept.getVin() != null)) {
				TransferAcceptedInfo accept1 = accept.findByVin(accept.getVin());
				if (accept1 != null) {
					
					if(accept1.getCheckUserid() == 0||accept1.getStatus()==18){
						
					}else{
						flags = "2";
						logger.info("VIN码为" + accept.getVin()+ "的车辆，目前已经处于过户中不能再次查验照相！");
						controller.commit();
						return flags;
					}
					
				}
			}
			
			if (!"".equals(accept.getLicensePlate())&& accept.getLicensePlate() != null) {
				TransferAcceptedInfo accepts = accept.findByLicenseplate(accept.getLicensePlate());
				if (accepts != null) {
					if(accepts.getCheckUserid() == 0 ||accepts.getStatus() == 18){
						
					}else{
						flags = "2";
						logger.info("车牌号码为" + accept.getLicensePlate()+ "的车辆，目前已经处于过户中不能再次查验照相！");
						controller.commit();
						return flags;
					}
					
				}
			}
			
			/*********************************************20170316 101接口修改begin******************************************************************************************************************/
			String licensePlate = accept.getLicensePlate();
			String vin = accept.getVin();
			String cy_cardTypeStr = accept.getCy_cardType();
			int cy_cardType = Integer.parseInt(cy_cardTypeStr);
			String photo_1 = "";
			String photo1Code = accept.getPhoto_1();
			/*if(licensePlate!= null && !licensePlate.isEmpty()){
				photo_1 = imageTool(licensePlate.substring(3), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
			}else{
				photo_1 = imageTool(vin, "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
			}*/
//			Sequence seq = Sequence.getInstance();
//			String serialone = seq.getSerial(6);
//			photo_1 = imageTool(serialone, "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
			
			
			if(licensePlate != null && !licensePlate.isEmpty()){
				TransferAcceptedInfoDto transferAcceptedInfoDto = new TransferAcceptedInfoDto();
				transferAcceptedInfoDto.setLicensePlate(licensePlate);
				TransferAcceptedInfoDaoImp transferAcceptedInfoDao = (TransferAcceptedInfoDaoImp) TransferAcceptedInfoDaoImp.getInstance(TmsDao.TMS_TRANSFER_ACCEPTED_INFO);
				TransferAcceptedInfoDto transferAcceptedInfo = transferAcceptedInfoDao.selectNumbesByLicensePlateOrVin(transferAcceptedInfoDto);
				//
				if(transferAcceptedInfo != null && (transferAcceptedInfo.getCheckUserid() == 0 || transferAcceptedInfo.getStatus() == 18)){
					//如果picChangeNum为空，变成0
					transferAcceptedInfoDao.updatePicChangeNumWhenNull(transferAcceptedInfo);
					//更新 过户业务基本信息表 (tms_transfer_accepted_info)
					photo_1 = imageTool(transferAcceptedInfo.getSerial(), "1",photo1Code,Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					transferAcceptedInfo.setPhoto_1(photo_1);
					transferAcceptedInfoDao.updatePhoto1BySerial(transferAcceptedInfo);
					//插入 过户流程操作记录表（tms_transfer_process_history）
					TransferProcessHistoryDto transferProcessHistoryDto = new TransferProcessHistoryDto();
					transferProcessHistoryDto.setBusinessType(33);
					transferProcessHistoryDto.setInsertUserId(1);
					String serial =transferAcceptedInfo.getSerial();
					transferProcessHistoryDto.setSerial(serial);
					TransferProcessHistoryDaoImp transferProcessHistoryDao = (TransferProcessHistoryDaoImp) TransferProcessHistoryDaoImp.getInstance(TmsDao.TMS_TRANSFER_PROCESS_HISTORY);
				    transferProcessHistoryDao.insertHisInfoBySerial(transferProcessHistoryDto);
				}else{
					//插入 过户业务基本信息表 (tms_transfer_accepted_info)
					String serial = Sequence.getInstance().getSerial(6);
					transferAcceptedInfoDto.setSerial(serial);
					transferAcceptedInfoDto.setMarketType(2);
					transferAcceptedInfoDto.setLicensePlate(licensePlate);
					transferAcceptedInfoDto.setCardType(cy_cardType);
					transferAcceptedInfoDto.setCarClass(2);
					photo_1 = imageTool(serial, "1",photo1Code,Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					transferAcceptedInfoDto.setPhoto_1(photo_1);
					if(cy_cardType == 0){
						transferAcceptedInfoDto.setLicensePlateCol("2");
					}else if(cy_cardType == 1){
						transferAcceptedInfoDto.setLicensePlateCol("1");
					}
					transferAcceptedInfoDto.setStatus(1);
					transferAcceptedInfoDto.setInsertUserid(1);
					transferAcceptedInfoDto.setUpdateUserId(1);
					transferAcceptedInfoDto.setVinNum("1");
					transferAcceptedInfoDto.setEngineNum("1");
					transferAcceptedInfoDto.setBrandModel("1");
					transferAcceptedInfoDto.setPlateOrTireExterior("1");
					transferAcceptedInfoDto.setTireIntact("1");
					transferAcceptedInfoDto.setSeatBelt("1");
					transferAcceptedInfoDao.insertCarInfoAtWX(transferAcceptedInfoDto);
					
					//插入 过户流程操作记录表（tms_transfer_process_history）
					TransferProcessHistoryDto transferProcessHistoryDto = new TransferProcessHistoryDto();
					transferProcessHistoryDto.setSerial(serial);
					transferProcessHistoryDto.setBusinessType(1);
					transferProcessHistoryDto.setInsertUserId(1);
					TransferProcessHistoryDaoImp transferProcessHistoryDao = (TransferProcessHistoryDaoImp) TransferProcessHistoryDaoImp.getInstance(TmsDao.TMS_TRANSFER_PROCESS_HISTORY);
					transferProcessHistoryDao.insertHisInfoBySerial(transferProcessHistoryDto);
					
					//插入 tms_transfer_finance_info（过户业务财务收费信息表）
					TransferFinanceInfoDaoImp transferFinanceInfoDao = (TransferFinanceInfoDaoImp) TransferFinanceInfoDaoImp.getInstance(TmsDao.TMS_TRANSFER_FINANCE_INFO);
					transferFinanceInfoDao.insertFinanceByInner(serial);
					//
//					CollectCarInfoImpl collectCarInfoDao = (CollectCarInfoImpl) CollectCarInfoImpl.getInstance(TmsDao.TMS_MARKET_CAR_INFO);
//					MarketCarInfoDto marketCarInfoDto = collectCarInfoDao.findMarketCarInfoListByLicensePlate(licensePlate);
//					//是库存车辆
//					if(marketCarInfoDto != null){
//						MarketCarServiceDto marketCarServiceDto = new MarketCarServiceDto();
//						String serviceSerial = marketCarInfoDto.getSerial();
//						marketCarServiceDto = collectCarInfoDao.findMarketCarServiceBySerial(serviceSerial);
//						//更新 过户业务基本信息表（tms_transfer_accepted_info）
//						TransferAcceptedInfoDto transferAcceptedInfoHasNum = new TransferAcceptedInfoDto();
//						transferAcceptedInfoHasNum.setSerial(serial);
//						transferAcceptedInfoHasNum.setMarketType(1);
//						transferAcceptedInfoHasNum.setTransferPrice(marketCarServiceDto.getTransferPrice());
//						transferAcceptedInfoHasNum.setBasicCarId(marketCarInfoDto.getSerial());
//						transferAcceptedInfoHasNum.setVin(marketCarInfoDto.getVin());
//						transferAcceptedInfoHasNum.setVendorId(marketCarInfoDto.getVendorId());
//						transferAcceptedInfoHasNum.setBrandId(marketCarInfoDto.getBrandId());
//						transferAcceptedInfoHasNum.setCarStyleId(marketCarInfoDto.getCarStyleId());
//						transferAcceptedInfoHasNum.setCarName(marketCarInfoDto.getCarName());
//						transferAcceptedInfoHasNum.setIsMatch(marketCarInfoDto.getIsMatch());
//						/*transferAcceptedInfoHasNum.setPhoto_1(marketCarInfoDto.getPhoto_1());*/
//						transferAcceptedInfoHasNum.setMemberId(String.valueOf(marketCarInfoDto.getMemberId()));
//						transferAcceptedInfoDao.updateAcceptedInfoBySerial(transferAcceptedInfoHasNum);
//						//插入 过户流程操作记录表（tms_transfer_process_history）
//						if(marketCarServiceDto.getCheckPrice()==1){//modify by huangwei
//							TransferProcessHistoryDto transferProcessHistoryHasNum = new TransferProcessHistoryDto();
//							transferProcessHistoryHasNum.setSerial(serial);
//							transferProcessHistoryHasNum.setBusinessType(8);
//							transferProcessHistoryHasNum.setInsertUserId(1);
//						    transferProcessHistoryDao.insertHisInfoBySerial(transferProcessHistoryHasNum);
//						}
//						TransferFinanceInfoDto transferFinanceInfoDto = new TransferFinanceInfoDto();
//						//更新  tms_transfer_finance_info（过户业务的财务收费信息表）
//						if(marketCarServiceDto.getCheckPrice()==1){//modify by huangwei
//							transferFinanceInfoDto.setSerial(serial);
//							transferFinanceInfoDto.setCheckPrice(marketCarServiceDto.getTransferPrice());//modify by huangwei
//							transferFinanceInfoDto.setCheckPriceUserId(1);
//							transferFinanceInfoDto.setCheckPriceChargeType(3);
//							transferFinanceInfoDao.updateFinanceInfoAtWXByCheckPrice(transferFinanceInfoDto);
//							
//						}
//						
//						//
//						transferFinanceInfoDto.setSerial(serial);
//						transferFinanceInfoDto.setTransferPrice(0);
//						transferFinanceInfoDto.setTransferPriceUserId(1);
//						transferFinanceInfoDto.setTransferPriceChargeType(3);
//						transferFinanceInfoDao.updateFinanceInfoAtWXByTransferPrice(transferFinanceInfoDto);
//						
//						MarketCarServiceDto marketCarServiceDtoHasNum = new MarketCarServiceDto();
//						marketCarServiceDtoHasNum.setSerial(marketCarServiceDto.getSerial());
//						marketCarServiceDtoHasNum.setCheckStatus(1);
//						marketCarServiceDtoHasNum.setCheckImgPath(null);
//						marketCarServiceDtoHasNum.setCheckUser(null);
//						marketCarServiceDtoHasNum.setCheckTime(null);
//						marketCarServiceDtoHasNum.setCheckValidTime(null);
//						marketCarServiceDtoHasNum.setIsValid(3);
//						if(marketCarServiceDto.getCheckPrice() == 1) marketCarServiceDtoHasNum.setCheckPrice(2);//modify by huangwei
//						else  marketCarServiceDtoHasNum.setCheckPrice(marketCarServiceDto.getCheckPrice());
//						marketCarServiceDtoHasNum.setTransferPrice(marketCarServiceDto.getTransferPrice());
//						collectCarInfoDao.updateMarketCarInfoService(marketCarServiceDtoHasNum);
//						
//						//401接口准备
//						TransferAcceptedInfoDto obj = transferAcceptedInfoDao.findTransfeAcceptedInfoBy401(serial);
//						
//						//需求说明本_tms_web.xlsx/微信平台同步接口/过户同步的接口编号：401
//						CheckPhotographyInfoBo checkPhotographyInfoBo = new CheckPhotographyInfoBo();
//						checkPhotographyInfoBo.setSerial(obj.getSerial());//车辆流水号
//						checkPhotographyInfoBo.setMarketType(obj.getMarketType());//车辆库存类型
//						checkPhotographyInfoBo.setLicensePlate(obj.getLicensePlate());//车牌号码
//						checkPhotographyInfoBo.setCy_cardType(obj.getCy_cardType());//号牌种类
//						checkPhotographyInfoBo.setCarClass(obj.getCarClass());//车辆分类
//						checkPhotographyInfoBo.setCarOwner(null);//原车主姓名
//						checkPhotographyInfoBo.setLicenseType(obj.getLicensePlateCol());//号牌颜色
//						checkPhotographyInfoBo.setBasicCarId(obj.getBasicCarId());//车辆编号
//						checkPhotographyInfoBo.setVin(obj.getVin());//车架号
//						checkPhotographyInfoBo.setVendorId(obj.getVendorId());//车辆品牌Id
//						checkPhotographyInfoBo.setBrandId(obj.getBrandId());//车系Id
//						checkPhotographyInfoBo.setCarStyleId(obj.getCarStyleId());//车辆款式Id
//						checkPhotographyInfoBo.setCarName(obj.getCarName());//车辆名称
//						checkPhotographyInfoBo.setDetailStatus(1);//车辆过户状态
//						checkPhotographyInfoBo.setIsMatch(obj.getIsMatch());//车款是否配对
//						checkPhotographyInfoBo.setPhoto_1(obj.getPhoto_1());//查验照片
//						checkPhotographyInfoBo.setMemberId(obj.getMemberId());//商户会员ID
//						checkPhotographyInfoBo.setStatus(2);//车辆过户状态
//						TmsConfigureDaoimp tmsConfigureDao = (TmsConfigureDaoimp) TmsConfigureDaoimp.getInstance(TmsDao.TMS_CONFIGURE);
//						String userMarket = tmsConfigureDao.getConfig("maketNo");//过户市场
//						checkPhotographyInfoBo.setUserMarket(userMarket);
//						
//					    WeChatMqApi.getInstance().call(checkPhotographyInfoBo);
//						
//					}else{
//						//未关联库存车辆
//						//插入 非库存车辆信息表
//						TransferPersonalCarInfoDto transferPersonalCarInfoDto = new TransferPersonalCarInfoDto();
//						String personSerial = Sequence.getInstance().getSerial(5);
//						transferPersonalCarInfoDto.setSerial(personSerial);
//						transferPersonalCarInfoDto.setStatus(3);
//						transferPersonalCarInfoDto.setLicensePlate(licensePlate);
//						transferPersonalCarInfoDto.setInsertUserId(1);
//						transferPersonalCarInfoDto.setUpdateUserId(1);
//						TransferPersonalCarInfoDaoImp transferPersonalCarInfoDao = (TransferPersonalCarInfoDaoImp) TransferPersonalCarInfoDaoImp.getInstance(TmsDao.TMS_TRANSFER_PERSONALCAR_INFO);
//						transferPersonalCarInfoDao.insertCarBaseInfoAtWX(transferPersonalCarInfoDto);
//						
//						//更新 过户业务基本信息表（tms_transfer_accepted_info）
//						TransferAcceptedInfoDto obj = new TransferAcceptedInfoDto();
//						obj.setBasicCarId(personSerial);
//						obj.setSerial(serial);
//						transferAcceptedInfoDao.updateBasicCarIdBySerial(obj);
//						//需求说明本_tms_web.xlsx/微信平台同步接口/过户同步的接口编号：401
//						//401接口准备
//						TransferAcceptedInfoDto obj401 = transferAcceptedInfoDao.findTransfeAcceptedInfoBy401(serial);
//						
//						CheckPhotographyInfoBo checkPhotographyInfoBo = new CheckPhotographyInfoBo();
//						checkPhotographyInfoBo.setSerial(obj401.getSerial());//车辆流水号
//						checkPhotographyInfoBo.setMarketType(obj401.getMarketType());//车辆库存类型
//						checkPhotographyInfoBo.setLicensePlate(obj401.getLicensePlate());//车牌号码
//						checkPhotographyInfoBo.setCy_cardType(obj401.getCy_cardType());//号牌种类
//						checkPhotographyInfoBo.setCarClass(obj401.getCarClass());//车辆分类
//						checkPhotographyInfoBo.setCarOwner(null);//原车主姓名
//						checkPhotographyInfoBo.setLicenseType(obj401.getLicensePlateCol());//号牌颜色
//						checkPhotographyInfoBo.setBasicCarId(personSerial);//车辆编号
//						checkPhotographyInfoBo.setVin(obj401.getVin());//车架号
//						checkPhotographyInfoBo.setVendorId(obj401.getVendorId());//车辆品牌Id
//						checkPhotographyInfoBo.setBrandId(obj401.getBrandId());//车系Id
//						checkPhotographyInfoBo.setCarStyleId(obj401.getCarStyleId());//车辆款式Id
//						checkPhotographyInfoBo.setCarName(obj401.getCarName());//车辆名称
//						checkPhotographyInfoBo.setDetailStatus(1);//车辆过户状态
//						checkPhotographyInfoBo.setIsMatch(obj401.getIsMatch());//车款是否配对
//						checkPhotographyInfoBo.setPhoto_1(obj401.getPhoto_1());//查验照片
//						checkPhotographyInfoBo.setMemberId(obj401.getMemberId());//商户会员ID
//						checkPhotographyInfoBo.setStatus(2);//车辆过户状态
//						TmsConfigureDaoimp tmsConfigureDao = (TmsConfigureDaoimp) TmsConfigureDaoimp.getInstance(TmsDao.TMS_CONFIGURE);
//						String userMarket = tmsConfigureDao.getConfig("maketNo");//过户市场
//						checkPhotographyInfoBo.setUserMarket(userMarket);
//					    WeChatMqApi.getInstance().call(checkPhotographyInfoBo);
//						
//					}
					
				}
				
			}
			else if(vin !=null && !vin.isEmpty()){
				TransferAcceptedInfoDto transferAcceptedInfoDto = new TransferAcceptedInfoDto();
				transferAcceptedInfoDto.setVin(vin);
				TransferAcceptedInfoDaoImp transferAcceptedInfoDao = (TransferAcceptedInfoDaoImp) TransferAcceptedInfoDaoImp.getInstance(TmsDao.TMS_TRANSFER_ACCEPTED_INFO);
				TransferAcceptedInfoDto transferAcceptedInfo = transferAcceptedInfoDao.selectNumbesByLicensePlateOrVin(transferAcceptedInfoDto);
				if(transferAcceptedInfo != null && (transferAcceptedInfo.getCheckUserid() == 0 || transferAcceptedInfo.getStatus() == 18)){
					//更新 过户业务基本信息表 (tms_transfer_accepted_info)
					photo_1 = imageTool(transferAcceptedInfo.getSerial(), "1",photo1Code,Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					transferAcceptedInfo.setPhoto_1(photo_1);
					//如果picChangeNum为空，变成0
					transferAcceptedInfoDao.updatePicChangeNumWhenNull(transferAcceptedInfo);
					transferAcceptedInfoDao.updatePhoto1BySerial(transferAcceptedInfo);
					//插入 过户流程操作记录表（tms_transfer_process_history）
					TransferProcessHistoryDto transferProcessHistoryDto = new TransferProcessHistoryDto();
					transferProcessHistoryDto.setBusinessType(33);
					transferProcessHistoryDto.setInsertUserId(1);
					String serial =transferAcceptedInfo.getSerial();
					transferProcessHistoryDto.setSerial(serial);
					TransferProcessHistoryDaoImp transferProcessHistoryDao = (TransferProcessHistoryDaoImp) TransferProcessHistoryDaoImp.getInstance(TmsDao.TMS_TRANSFER_PROCESS_HISTORY);
				    transferProcessHistoryDao.insertHisInfoBySerial(transferProcessHistoryDto);
				}else{
					//插入 过户业务基本信息表 (tms_transfer_accepted_info)
					String serial = Sequence.getInstance().getSerial(6);
					transferAcceptedInfoDto.setSerial(serial);
					transferAcceptedInfoDto.setMarketType(2);
					transferAcceptedInfoDto.setVin(vin);
					transferAcceptedInfoDto.setCardType(cy_cardType);
					transferAcceptedInfoDto.setCarClass(1);
					photo_1 = imageTool(serial, "1",photo1Code,Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					transferAcceptedInfoDto.setPhoto_1(photo_1);
					if(cy_cardType == 0){
						transferAcceptedInfoDto.setLicensePlateCol("2");
					}else if(cy_cardType == 1){
						transferAcceptedInfoDto.setLicensePlateCol("1");
					}
					transferAcceptedInfoDto.setStatus(1);
					transferAcceptedInfoDto.setInsertUserid(1);
					transferAcceptedInfoDto.setUpdateUserId(1);
					transferAcceptedInfoDto.setVinNum("1");
					transferAcceptedInfoDto.setEngineNum("1");
					transferAcceptedInfoDto.setBrandModel("1");
					transferAcceptedInfoDto.setPlateOrTireExterior("1");
					transferAcceptedInfoDto.setTireIntact("1");
					transferAcceptedInfoDto.setSeatBelt("1");
					transferAcceptedInfoDao.insertCarInfoAtWX(transferAcceptedInfoDto);
					
					//插入 过户流程操作记录表（tms_transfer_process_history）
					TransferProcessHistoryDto transferProcessHistoryDto = new TransferProcessHistoryDto();
					transferProcessHistoryDto.setSerial(serial);
					transferProcessHistoryDto.setBusinessType(1);
					transferProcessHistoryDto.setInsertUserId(1);
					TransferProcessHistoryDaoImp transferProcessHistoryDao = (TransferProcessHistoryDaoImp) TransferProcessHistoryDaoImp.getInstance(TmsDao.TMS_TRANSFER_PROCESS_HISTORY);
					transferProcessHistoryDao.insertHisInfoBySerial(transferProcessHistoryDto);
					
					//插入 tms_transfer_finance_info（过户业务财务收费信息表）
					TransferFinanceInfoDaoImp transferFinanceInfoDao = (TransferFinanceInfoDaoImp) TransferFinanceInfoDaoImp.getInstance(TmsDao.TMS_TRANSFER_FINANCE_INFO);
					transferFinanceInfoDao.insertFinanceByInner(serial);
					
//					CollectCarInfoImpl collectCarInfoDao = (CollectCarInfoImpl) CollectCarInfoImpl.getInstance(TmsDao.TMS_MARKET_CAR_INFO);
//					MarketCarInfoDto marketCarInfoDto = collectCarInfoDao.findMarketCarInfoListByVinAll(vin);
//					if(marketCarInfoDto != null){
//						//更新 过户业务基本信息表（tms_transfer_accepted_info）
//						TransferAcceptedInfoDto transferAcceptedInfoHasNum = new TransferAcceptedInfoDto();
//						transferAcceptedInfoHasNum.setSerial(serial);
//						transferAcceptedInfoHasNum.setMarketType(1);
//						transferAcceptedInfoHasNum.setBasicCarId(marketCarInfoDto.getSerial());
//						transferAcceptedInfoHasNum.setVin(marketCarInfoDto.getVin());
//						transferAcceptedInfoHasNum.setVendorId(marketCarInfoDto.getVendorId());
//						transferAcceptedInfoHasNum.setBrandId(marketCarInfoDto.getBrandId());
//						transferAcceptedInfoHasNum.setCarStyleId(marketCarInfoDto.getCarStyleId());
//						transferAcceptedInfoHasNum.setCarName(marketCarInfoDto.getCarName());
//						transferAcceptedInfoHasNum.setIsMatch(marketCarInfoDto.getIsMatch());
//						/*transferAcceptedInfoHasNum.setPhoto_1(marketCarInfoDto.getPhoto_1());*/
//						transferAcceptedInfoHasNum.setMemberId(String.valueOf(marketCarInfoDto.getMemberId()));
//						transferAcceptedInfoDao.updateAcceptedInfoBySerialNewCar(transferAcceptedInfoHasNum);
//						
//						//更新  tms_transfer_finance_info（过户业务的财务收费信息表）
//						MarketCarServiceDto marketCarServiceDto = new MarketCarServiceDto();
//						String serviceSerial = marketCarInfoDto.getSerial();
//						marketCarServiceDto = collectCarInfoDao.findMarketCarServiceBySerial(serviceSerial);
//						TransferFinanceInfoDto transferFinanceInfoDto = new TransferFinanceInfoDto();
//						if(marketCarServiceDto.getCheckPrice() ==1){//modify by huangwei
//							transferFinanceInfoDto.setSerial(serial);
//							transferFinanceInfoDto.setCheckPrice(marketCarServiceDto.getTransferPrice());
//							transferFinanceInfoDto.setCheckPriceUserId(1);
//							transferFinanceInfoDto.setCheckPriceChargeType(3);
//							transferFinanceInfoDao.updateFinanceInfoAtWXByCheckPrice(transferFinanceInfoDto);
//						}
//						//更新 库存车辆业务表（tms_market_car_service）
//						MarketCarServiceDto marketCarServiceDtoHasNum = new MarketCarServiceDto();
//						marketCarServiceDtoHasNum.setSerial(marketCarServiceDto.getSerial());
//						marketCarServiceDtoHasNum.setCheckStatus(1);
//						marketCarServiceDtoHasNum.setCheckImgPath(null);
//						marketCarServiceDtoHasNum.setCheckUser(null);
//						marketCarServiceDtoHasNum.setCheckTime(null);
//						marketCarServiceDtoHasNum.setCheckValidTime(null);
//						marketCarServiceDtoHasNum.setIsValid(3);
//						if(marketCarServiceDto.getCheckPrice() == 1) marketCarServiceDtoHasNum.setCheckPrice(2);//modify by huangwei
//						else  marketCarServiceDtoHasNum.setCheckPrice(marketCarServiceDto.getCheckPrice());
//						marketCarServiceDtoHasNum.setTransferPrice(marketCarServiceDto.getTransferPrice());
//						collectCarInfoDao.updateMarketCarInfoService(marketCarServiceDtoHasNum);
//						//需求说明本_tms_web.xlsx/微信平台同步接口/过户同步的接口编号：401
//						
//						//401接口准备
//						TransferAcceptedInfoDto obj = transferAcceptedInfoDao.findTransfeAcceptedInfoBy401(serial);
//						//需求说明本_tms_web.xlsx/微信平台同步接口/过户同步的接口编号：401
//						CheckPhotographyInfoBo checkPhotographyInfoBo = new CheckPhotographyInfoBo();
//						checkPhotographyInfoBo.setSerial(obj.getSerial());//车辆流水号
//						checkPhotographyInfoBo.setMarketType(obj.getMarketType());//车辆库存类型
//						checkPhotographyInfoBo.setLicensePlate(obj.getLicensePlate());//车牌号码
//						checkPhotographyInfoBo.setCy_cardType(obj.getCy_cardType());//号牌种类
//						checkPhotographyInfoBo.setCarClass(obj.getCarClass());//车辆分类
//						checkPhotographyInfoBo.setCarOwner(null);//原车主姓名
//						checkPhotographyInfoBo.setLicenseType(obj.getLicensePlateCol());//号牌颜色
//						checkPhotographyInfoBo.setBasicCarId(obj.getBasicCarId());//车辆编号
//						checkPhotographyInfoBo.setVin(obj.getVin());//车架号
//						checkPhotographyInfoBo.setVendorId(obj.getVendorId());//车辆品牌Id
//						checkPhotographyInfoBo.setBrandId(obj.getBrandId());//车系Id
//						checkPhotographyInfoBo.setCarStyleId(obj.getCarStyleId());//车辆款式Id
//						checkPhotographyInfoBo.setCarName(obj.getCarName());//车辆名称
//						checkPhotographyInfoBo.setDetailStatus(1);//车辆过户状态
//						checkPhotographyInfoBo.setIsMatch(obj.getIsMatch());//车款是否配对
//						checkPhotographyInfoBo.setPhoto_1(obj.getPhoto_1());//查验照片
//						checkPhotographyInfoBo.setMemberId(obj.getMemberId());//商户会员ID
//						checkPhotographyInfoBo.setStatus(2);//车辆过户状态
//						TmsConfigureDaoimp tmsConfigureDao = (TmsConfigureDaoimp) TmsConfigureDaoimp.getInstance(TmsDao.TMS_CONFIGURE);
//						String userMarket = tmsConfigureDao.getConfig("maketNo");//过户市场
//						checkPhotographyInfoBo.setUserMarket(userMarket);
//						
//					    WeChatMqApi.getInstance().call(checkPhotographyInfoBo);
//					    
//					}else{
//						//未关联库存车辆
//						//插入 非库存车辆信息表
//						TransferPersonalCarInfoDto transferPersonalCarInfoDto = new TransferPersonalCarInfoDto();
//						String personSerial = Sequence.getInstance().getSerial(5);
//						transferPersonalCarInfoDto.setSerial(personSerial);
//						transferPersonalCarInfoDto.setStatus(3);
//						transferPersonalCarInfoDto.setVin(vin);
//						transferPersonalCarInfoDto.setInsertUserId(1);
//						transferPersonalCarInfoDto.setUpdateUserId(1);
//						TransferPersonalCarInfoDaoImp transferPersonalCarInfoDao = (TransferPersonalCarInfoDaoImp) TransferPersonalCarInfoDaoImp.getInstance(TmsDao.TMS_TRANSFER_PERSONALCAR_INFO);
//						transferPersonalCarInfoDao.insertCarBaseInfoAtWX(transferPersonalCarInfoDto);
//						//更新 过户业务基本信息表（tms_transfer_accepted_info）
//						TransferAcceptedInfoDto obj = new TransferAcceptedInfoDto();
//						obj.setBasicCarId(personSerial);
//						obj.setSerial(serial);
//						transferAcceptedInfoDao.updateBasicCarIdBySerial(obj);
//						//需求说明本_tms_web.xlsx/微信平台同步接口/过户同步的接口编号：401
//						
//						//401接口准备
//						TransferAcceptedInfoDto obj401 = transferAcceptedInfoDao.findTransfeAcceptedInfoBy401(serial);
//						
//						CheckPhotographyInfoBo checkPhotographyInfoBo = new CheckPhotographyInfoBo();
//						checkPhotographyInfoBo.setSerial(obj401.getSerial());//车辆流水号
//						checkPhotographyInfoBo.setMarketType(obj401.getMarketType());//车辆库存类型
//						checkPhotographyInfoBo.setLicensePlate(obj401.getLicensePlate());//车牌号码
//						checkPhotographyInfoBo.setCy_cardType(obj401.getCy_cardType());//号牌种类
//						checkPhotographyInfoBo.setCarClass(obj401.getCarClass());//车辆分类
//						checkPhotographyInfoBo.setCarOwner(null);//原车主姓名
//						checkPhotographyInfoBo.setLicenseType(obj401.getLicensePlateCol());//号牌颜色
//						checkPhotographyInfoBo.setBasicCarId(personSerial);//车辆编号
//						checkPhotographyInfoBo.setVin(obj401.getVin());//车架号
//						checkPhotographyInfoBo.setVendorId(obj401.getVendorId());//车辆品牌Id
//						checkPhotographyInfoBo.setBrandId(obj401.getBrandId());//车系Id
//						checkPhotographyInfoBo.setCarStyleId(obj401.getCarStyleId());//车辆款式Id
//						checkPhotographyInfoBo.setCarName(obj401.getCarName());//车辆名称
//						checkPhotographyInfoBo.setDetailStatus(1);//车辆过户状态
//						checkPhotographyInfoBo.setIsMatch(obj401.getIsMatch());//车款是否配对
//						checkPhotographyInfoBo.setPhoto_1(obj401.getPhoto_1());//查验照片
//						checkPhotographyInfoBo.setMemberId(obj401.getMemberId());//商户会员ID
//						checkPhotographyInfoBo.setStatus(2);//车辆过户状态
//						TmsConfigureDaoimp tmsConfigureDao = (TmsConfigureDaoimp) TmsConfigureDaoimp.getInstance(TmsDao.TMS_CONFIGURE);
//						String userMarket = tmsConfigureDao.getConfig("maketNo");//过户市场
//						checkPhotographyInfoBo.setUserMarket(userMarket);
//					    WeChatMqApi.getInstance().call(checkPhotographyInfoBo);
//					}
				}
			}
			
		/*****************************************************************************20170316 101接口修改end***********************************************************************************************/ 
			
			controller.commit();
			return flags;
		} catch (TransactionException e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				// TODO Auto-generated catch block 
				e1.printStackTrace();
			}
			e.printStackTrace();
		}
		return flags;
	}

	/**
	 * @param accept
	 * @throws TmsDaoException
	 * 车辆查验
	 */
	public static  String checkCar(TransferAcceptedInfo accept)
			throws TmsDaoException {
		String flags = "1";
		TxController controller = TxController.getTxController();
		try {
			controller.begin();
			// ① 是否正处于过户中
			if (accept.getLicensePlate() != null&& !"".equals(accept.getLicensePlate())) {
				TransferAcceptedInfo accept1 = accept.findByLicenseplate(accept.getLicensePlate());
				if (accept1 != null) {
					if (accept1.getCarClass() == 2 && accept1.getStatus() == 16) {
						flags = "2";
						PicChangeHistory picChangeHistory = new PicChangeHistory();
						picChangeHistory.setLicensePlate(accept.getLicensePlate());
						picChangeHistory.setInsertUserId(accept.getInsertUserid());
						picChangeHistory.setOperateFlag(1);
						picChangeHistory.setRemark("车辆处于过户中，不能再次查验照相.");
						picChangeHistory.setSuccessFlag(2);
						picChangeHistory.insertPicChange(picChangeHistory);
						logger.info("车牌号码为" + accept.getLicensePlate()+ "的车辆，目前已经处于过户中不能再次查验照相！");
						controller.commit();
						return flags;
					}
				}
			}
			if (("".equals(accept.getLicensePlate()) || accept.getLicensePlate() == null)&& (!"".equals(accept.getVin()) && accept.getVin() != null)) {
				TransferAcceptedInfo accept1 = accept.findByVin(accept.getVin());
				if (accept1 != null) {
					flags = "2";
					PicChangeHistory picChangeHistory = new PicChangeHistory();
					picChangeHistory.setLicensePlate(accept.getLicensePlate());
					picChangeHistory.setInsertUserId(accept.getInsertUserid());
					picChangeHistory.setOperateFlag(1);
					picChangeHistory.setRemark("车辆处于过户中(新车)，不能再次查验照相.");
					picChangeHistory.setSuccessFlag(2);
					picChangeHistory.insertPicChange(picChangeHistory);
					logger.info("VIN码为" + accept.getVin()+ "的车辆，目前已经处于过户中不能再次查验照相！");
					controller.commit();
					return flags;
				}
			}
			// ② 二手车查验库存关联上
			if (!"".equals(accept.getLicensePlate())) {
				Car car = Car.getInstance();
				TransferPersonalCarInfo personal = new TransferPersonalCarInfo();
				car = car.searchAllCarByLicensePlate(accept.getLicensePlate());
				if (car != null) {
//					if (car.getRegisterStatus() == 1 || car.getRegisterStatus() == 2) {
					if (car.getRegisterStatus() !=3 && car.getRegisterStatus() !=4 ) {//modify by huangwei
						car.setStatus(3);
						if(accept.getVin()!=null&&!"".equals(accept.getVin()))
						{
							car.setVin(accept.getVin());
						}else{
							accept.setVin(car.getVin());
						}
						if(accept.getCy_cardType()!=null&&!"".equals(accept.getCy_cardType()))
						{
							car.setCardType(Integer.parseInt(accept.getCy_cardType()));
						}
						// 处理四长图片
						if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
							String patch1 = imageTool(car.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							car.setPhoto_1(patch1);
						} else {
							logger.info("库存图片1为空!");
							car.setPhoto_1("");
						}
						if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
							String patch2 = imageTool(car.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							car.setPhoto_2(patch2);
						} else {
							logger.info("库存图片2为空!");
							car.setPhoto_2("");
						}
						if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
							String patch3 = imageTool(car.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							car.setPhoto_3(patch3);
						} else {
							logger.info("库存图片3为空!");
							car.setPhoto_3("");
						}
						if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
							String patch4 = imageTool(car.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							car.setPhoto_4(patch4);
						} else {
							logger.info("库存图片4为空!");
							car.setPhoto_4("");
						}
						car.setUpdateUserId(accept.getUpdateUserId());
						car.updateMarketCarInfo(car);
						

						accept.setCarClass(2);
						accept.setStatus(1);
						accept.setMarketType(1);
						accept.setBasicCarId(car.getSerial());
						accept.setUpdateUserId(accept.getInsertUserid());
						// 处理四长图片
						if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
							String patch1 = imageTool(accept.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_1(patch1);
						} else {
							logger.info("图片1为空!");
							accept.setPhoto_1("");
						}
						if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
							String patch2 = imageTool(accept.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_2(patch2);
						} else {
							logger.info("图片2为空!");
							accept.setPhoto_2("");
						}
						if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
							String patch3 = imageTool(accept.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_3(patch3);
						} else {
							logger.info("图片3为空!");
							accept.setPhoto_3("");
						}
						if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
							String patch4 = imageTool(accept.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_4(patch4);
						} else {
							logger.info("图片4为空!");
							accept.setPhoto_4("");
						}
						accept.updateAcceptInfoAtPad(accept);

						TransferProcessHistory his = new TransferProcessHistory();
						his.setSerial(accept.getSerial());
						his.setBusinessType(1);
						his.setInsertUserId(accept.getInsertUserid());
						his.insertHisInfoAtAssess(his);
						
//						workload:3.1.2 delete
//						// add by huangheli 2016/01/10 start
//						MobileMessage message = new MobileMessage();
//						message.putValue("Serial", accept.getSerial());
//						message.setMessage("pad查验 -[过户管理-车辆查验功能]接口,过户流水号为#Serial#过户信息不存在，无法同步TMS的pad查验照相（更新）");
//						transferDataSyn0071Bo bo = new transferDataSyn0071Bo();
//						bo.setMobileMessage(message);
//						bo.setSerial(accept.getSerial());
//						bo.setFunc(8);
//						bo.setStatus(2);
//						bo.setDetailStatus(1);
//						PullingExecutor.getInstance().submit(bo);
//						// add by huangheli 2016/01/10 end
						
					} else {
						// 向非库存表中插数据
						String pSerial = Sequence.getInstance().getSerial(5);
						//------------------------------------------提交线程  开启新线程
						controller.commit();
						controller.begin();
						personal.setSerial(pSerial);
						personal.setStatus(3);
						personal.setInsertUserId(accept.getInsertUserid());// 这块需要从user表中获取用户ID
						personal.setUpdateUserId(accept.getInsertUserid());
						if (accept.getCy_cardType() != null&& !"".equals(accept.getCy_cardType())) {
							personal.setCardType(Integer.parseInt(accept.getCy_cardType()));
						} else {
							personal.setCardType(0);
						}
						personal.setCarOwner(accept.getCarOwner());
						personal.setOwnerType(accept.getOwnerType());
						personal.setLicensePlate(accept.getLicensePlate());
						// 处理四长图片
						if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
							String patch1 = imageTool(pSerial, "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							personal.setPhoto_1(patch1);
						} else {
							logger.info("库存图片1为空!");
							personal.setPhoto_1("");
						}
						if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
							String patch2 = imageTool(pSerial, "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							personal.setPhoto_2(patch2);
						} else {
							logger.info("库存图片2为空!");
							personal.setPhoto_2("");
						}
						if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
							String patch3 = imageTool(pSerial, "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							personal.setPhoto_3(patch3);
						} else {
							logger.info("库存图片3为空!");
							personal.setPhoto_3("");
						}
						if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
							String patch4 = imageTool(pSerial, "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
							personal.setPhoto_4(patch4);
						} else {
							logger.info("库存图片4为空!");
							personal.setPhoto_4("");
						}
						personal.insertCarBaseInfoAtAssess(personal);

						// 插入过户信息
						String serial = Sequence.getInstance().getSerial(6);
						//------------------------------------------提交线程  开启新线程
						controller.commit();
						controller.begin();
						accept.setSerial(serial);
						accept.setBasicCarId(pSerial);
						accept.setMarketType(2);
						accept.setCarClass(2);
						accept.setStatus(1);

						// 处理四长图片
						if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
							String patch1 = imageTool(accept.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_1(patch1);
						} else {
							logger.info("图片1为空!");
							accept.setPhoto_1("");
						}
						if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
							String patch2 = imageTool(accept.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_2(patch2);
						} else {
							logger.info("图片2为空!");
							accept.setPhoto_2("");
						}
						if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
							String patch3 = imageTool(accept.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_3(patch3);
						} else {
							logger.info("图片3为空!");
							accept.setPhoto_3("");
						}
						if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
							String patch4 = imageTool(accept.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
							accept.setPhoto_4(patch4);
						} else {
							logger.info("图片4为空!");
							accept.setPhoto_4("");
						}
						accept.insertCarInfoAtPad(accept);

						TransferProcessHistory his = new TransferProcessHistory();
						his.setSerial(serial);
						his.setBusinessType(1);
						his.setInsertUserId(accept.getInsertUserid());
						his.insertHisInfoAtAssess(his);
						// 财务表
						TransferFinanceInfo finance = new TransferFinanceInfo();
						finance.insertFinanceByInner(serial);
						
						// add by huangheli 2016/01/10 start
						MobileMessage message = new MobileMessage();
						message.putValue("Serial", accept.getSerial());
						message.setMessage("pad查验 -[过户管理-车辆查验功能]接口,过户流水号为#Serial#过户信息已存在，无法同步TMS的pad车辆查验（插入）");
						TransferDataSyn0000Bo bo = new TransferDataSyn0000Bo();
						bo.setMobileMessage(message);
						bo.setSerial(accept.getSerial());
						bo.setBasicCarId(accept.getBasicCarId());
						bo.setLicensePlate(accept.getLicensePlate());
						bo.setDetailStatus(his.getBusinessType());
						bo.setMarketType(accept.getMarketType());
						bo.setMarket(Integer.parseInt(Registry.getConfig(TmsConstants.TMS_LOCAL)));
						PullingExecutor.getInstance().submit(bo);
						// add by huangheli 2016/01/10 end
					}
				} else {
					// 向非库存表中插数据
					String pSerial = Sequence.getInstance().getSerial(5);
					//------------------------------------------提交线程  开启新线程
					controller.commit();
					controller.begin();
					personal.setSerial(pSerial);
					personal.setStatus(3);
					personal.setInsertUserId(accept.getInsertUserid());// 这块需要从user表中获取用户ID
					personal.setUpdateUserId(accept.getInsertUserid());
					if (accept.getCy_cardType() != null
							&& !"".equals(accept.getCy_cardType())) {
						personal.setCardType(Integer.parseInt(accept
								.getCy_cardType()));
					} else {
						personal.setCardType(0);
					}
					personal.setCarOwner(accept.getCarOwner());
					personal.setOwnerType(accept.getOwnerType());
					personal.setLicensePlate(accept.getLicensePlate());
					if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
						String patch1 = imageTool(pSerial, "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						personal.setPhoto_1(patch1);
					} else {
						logger.info("库存图片1为空!");
						personal.setPhoto_1("");
					}
					if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
						String patch2 = imageTool(pSerial, "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						personal.setPhoto_2(patch2);
					} else {
						logger.info("库存图片2为空!");
						personal.setPhoto_2("");
					}
					if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
						String patch3 = imageTool(pSerial, "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						personal.setPhoto_3(patch3);
					} else {
						logger.info("库存图片3为空!");
						personal.setPhoto_3("");
					}
					if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
						String patch4 = imageTool(pSerial, "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						personal.setPhoto_4(patch4);
					} else {
						logger.info("库存图片4为空!");
						personal.setPhoto_4("");
					}
					personal.insertCarBaseInfoAtAssess(personal);

					// 插入过户信息
					String serial = Sequence.getInstance().getSerial(6);
					//------------------------------------------提交线程  开启新线程
					controller.commit();
					controller.begin();
					accept.setSerial(serial);
					accept.setBasicCarId(pSerial);
					accept.setMarketType(2);
					accept.setCarClass(2);
					accept.setStatus(1);
					// 处理四长图片
					if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
						String patch1 = imageTool(accept.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_1(patch1);
					} else {
						logger.info("图片1为空!");
						accept.setPhoto_1("");
					}
					if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
						String patch2 = imageTool(accept.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_2(patch2);
					} else {
						logger.info("图片2为空!");
						accept.setPhoto_2("");
					}
					if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
						String patch3 = imageTool(accept.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_3(patch3);
					} else {
						logger.info("图片3为空!");
						accept.setPhoto_3("");
					}
					if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
						String patch4 = imageTool(accept.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
						accept.setPhoto_4(patch4);
					} else {
						logger.info("图片4为空!");
						accept.setPhoto_4("");
					}
					accept.insertCarInfoAtPad(accept);

					TransferProcessHistory his = new TransferProcessHistory();
					his.setSerial(serial);
					his.setBusinessType(1);
					his.setInsertUserId(accept.getInsertUserid());
					his.insertHisInfoAtAssess(his);
					// 财务表
					TransferFinanceInfo finance = new TransferFinanceInfo();
					finance.insertFinanceByInner(serial);
					
					// add by huangheli 2016/01/10 start
					MobileMessage message = new MobileMessage();
					message.putValue("Serial", accept.getSerial());
					message.setMessage("pad查验 -[过户管理-车辆查验功能]接口,过户流水号为#Serial#过户信息已存在，无法同步TMS的pad车辆查验（插入）");
					TransferDataSyn0000Bo bo = new TransferDataSyn0000Bo();
					bo.setMobileMessage(message);
					bo.setSerial(accept.getSerial());
					bo.setBasicCarId(accept.getBasicCarId());
					bo.setLicensePlate(accept.getLicensePlate());
					bo.setDetailStatus(his.getBusinessType());
					bo.setMarketType(accept.getMarketType());
					bo.setMarket(Integer.parseInt(Registry.getConfig(TmsConstants.TMS_LOCAL)));
					PullingExecutor.getInstance().submit(bo);
					// add by huangheli 2016/01/10 end
				}
			}else{
				// ④ 新车处理
				String serial = Sequence.getInstance().getSerial(6);
				//------------------------------------------提交线程  开启新线程
				controller.commit();
				controller.begin();
				accept.setSerial(serial);
				accept.setCarClass(1);
				accept.setStatus(1);
				// 处理四长图片
				if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
					String patch1 = imageTool(accept.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accept.setPhoto_1(patch1);
				} else {
					logger.info("图片1为空!");
					accept.setPhoto_1("");
				}
				if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
					String patch2 = imageTool(accept.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accept.setPhoto_2(patch2);
				} else {
					logger.info("图片2为空!");
					accept.setPhoto_2("");
				}
				if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
					String patch3 = imageTool(accept.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accept.setPhoto_3(patch3);
				} else {
					logger.info("图片3为空!");
					accept.setPhoto_3("");
				}
				if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
					String patch4 = imageTool(accept.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accept.setPhoto_4(patch4);
				} else {
					logger.info("图片4为空!");
					accept.setPhoto_4("");
				}
				accept.insertCarInfoAtPad(accept);
				TransferProcessHistory his = new TransferProcessHistory();
				his.setSerial(serial);
				his.setBusinessType(1);
				his.setInsertUserId(accept.getInsertUserid());
				his.insertHisInfoAtAssess(his);
				// 收费表
				TransferFinanceInfo finance = new TransferFinanceInfo();
				finance.insertFinanceByInner(serial);
			}
			controller.commit();
			return flags;
		} catch (TransactionException e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				// TODO Auto-generated catch block 
				e1.printStackTrace();
			}			
			e.printStackTrace();
		}
		return flags;
	}

	/**
	 * 重新查验
	 * 
	 * @param accept
	 * @return
	 * @throws TmsDaoException
	 */
	public static  String checkAgain(TransferAcceptedInfo accept)
			throws TmsDaoException {
		String flags = "1";
		TxController controller = TxController.getTxController();
		try {
			controller.begin();
			TransferAcceptedInfo accepts = accept.getAcceptInfoBySerial(accept.getSerial(),"");
			if (accepts != null) {

				if(accepts.getCheckUserid() == 0 || accepts.getStatus() == 18){
					
				
				if(accepts.getMarketType() == 1)
				{
					//库存
					Car car = Car.getInstance();
					car = car.findCarBySerial(accepts.getBasicCarId());
					if(accept.getVin()!=null&&!"".equals(accept.getVin()))
					{
						car.setVin(accept.getVin());
					}else{
						accept.setVin(car.getVin());
					}
					if(accept.getCy_cardType()!=null&&!"".equals(accept.getCy_cardType()))
					{
						car.setCardType(Integer.parseInt(accept.getCy_cardType()));
					}
					// 处理四长图片
					if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
						String patch1 = imageTool(car.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						car.setPhoto_1(patch1);
					} else {
						logger.info("库存图片1为空!");
						car.setPhoto_1("");
					}
					if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
						String patch2 = imageTool(car.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						car.setPhoto_2(patch2);
					} else {
						logger.info("库存图片2为空!");
						car.setPhoto_2("");
					}
					if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
						String patch3 = imageTool(car.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						car.setPhoto_3(patch3);
					} else {
						logger.info("库存图片3为空!");
						car.setPhoto_3("");
					}
					if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
						String patch4 = imageTool(car.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						car.setPhoto_4(patch4);
					} else {
						logger.info("库存图片4为空!");
						car.setPhoto_4("");
					}
					car.setUpdateUserId(accept.getUpdateUserId());
					car.updateMarketCarInfo(car);
				}
				if(accepts.getMarketType() == 2)
				{
					//非库存
					TransferPersonalCarInfo person = new TransferPersonalCarInfo();
					person = person.getPersonalCarInfoBySerial(accepts.getBasicCarId());
					if(accept.getVin()!=null&&!"".equals(accept.getVin()))
					{
						person.setVin(accept.getVin());
					}
					if(accept.getCy_cardType()!=null&&!"".equals(accept.getCy_cardType()))
					{
						person.setCardType(Integer.parseInt(accept.getCy_cardType()));
					}
					// 处理四长图片
					if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
						String patch1 = imageTool(person.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						person.setPhoto_1(patch1);
					} else {
						logger.info("库存图片1为空!");
						person.setPhoto_1("");
					}
					if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
						String patch2 = imageTool(person.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						person.setPhoto_2(patch2);
					} else {
						logger.info("库存图片2为空!");
						person.setPhoto_2("");
					}
					if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
						String patch3 = imageTool(person.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						person.setPhoto_3(patch3);
					} else {
						logger.info("库存图片3为空!");
						person.setPhoto_3("");
					}
					if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
						String patch4 = imageTool(person.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY),Registry.getConfig(TmsConstants.UPLOAD_CONTEXT_ROOT_KEY));
						person.setPhoto_4(patch4);
					} else {
						logger.info("库存图片4为空!");
						person.setPhoto_4("");
					}
					person.setUpdateUserId(accept.getUpdateUserId());
					person.updateCarBaseInfo(person);		
				}
				accepts.setVinNum(accept.getVinNum());
				accepts.setEngineNum(accept.getEngineNum());
				accepts.setBrandModel(accept.getBrandModel());
				accepts.setCy_color(accept.getCy_color());
				accepts.setCy_passenger(accept.getCy_passenger());
				accepts.setCy_carType(accept.getCy_carType());
				accepts.setPlateOrTireExterior(accept.getPlateOrTireExterior());
				accepts.setTireIntact(accept.getTireIntact());
				accepts.setSeatBelt(accept.getSeatBelt());
				accepts.setNumberAxes(accept.getNumberAxes());
				accepts.setTireSize(accept.getTireSize());
				accepts.setLateralPortionOf(accept.getLateralPortionOf());
				accepts.setReflectiveMark(accept.getReflectiveMark());
				accepts.setFireExtinguisher(accept.getFireExtinguisher());
				accepts.setDrivingRecord(accept.getDrivingRecord());
				accepts.setSecurity(accept.getSecurity());
				accepts.setExternalMarking(accept.getExternalMarking());
				accepts.setSiren(accept.getSiren());
				accepts.setSecurityTechnology(accept.getSecurityTechnology());
				accepts.setCheckConclusion(accept.getCheckConclusion());
				accepts.setInsertUserid(accept.getInsertUserid());
				accepts.setUpdateUserId(accept.getUpdateUserId());
				accepts.setInsertTime(DateUtil.getStringToTimeStamp1(DateUtil.getCurrentTime()));

				// 处理四长图片
				if (accept.getPhoto_1() != null&& !"".equals(accept.getPhoto_1())) {
					String patch1 = imageTool(accept.getSerial(), "1",accept.getPhoto_1(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accepts.setPhoto_1(patch1);
				} else {
					logger.info("图片1为空!");
					accepts.setPhoto_1("");
				}
				if (accept.getPhoto_2() != null&& !"".equals(accept.getPhoto_2())) {
					String patch2 = imageTool(accept.getSerial(), "2",accept.getPhoto_2(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accepts.setPhoto_2(patch2);
				} else {
					logger.info("图片2为空!");
					accepts.setPhoto_2("");
				}
				if (accept.getPhoto_3() != null&& !"".equals(accept.getPhoto_3())) {
					String patch3 = imageTool(accept.getSerial(), "3",accept.getPhoto_3(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accepts.setPhoto_3(patch3);
				} else {
					logger.info("图片3为空!");
					accepts.setPhoto_3("");
				}
				if (accept.getPhoto_4() != null&& !"".equals(accept.getPhoto_4())) {
					String patch4 = imageTool(accept.getSerial(), "4",accept.getPhoto_4(),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY),Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY));
					accepts.setPhoto_4(patch4);
				} else {
					logger.info("图片4为空!");
					accepts.setPhoto_4("");
				}
				accepts.setPicChangeNum(accepts.getPicChangeNum() + 1);
				accepts.setPicChangeUserId(accept.getInsertUserid());
				accepts.updateAcceptInfoAtPad(accepts);
								
				TransferProcessHistory his = new TransferProcessHistory();
				his.setSerial(accept.getSerial());
				his.setBusinessType(33);
				his.setInsertUserId(accept.getInsertUserid());
				his.insertHisInfoAtAssess(his);
				
				PicChangeHistory picChangeHistory = new PicChangeHistory();
				picChangeHistory.setLicensePlate(accept.getLicensePlate());
				picChangeHistory.setInsertUserId(accept.getInsertUserid());
				picChangeHistory.setOperateFlag(2);
				picChangeHistory.setRemark("车辆重新查验成功.");
				picChangeHistory.setSuccessFlag(1);
				picChangeHistory.insertPicChange(picChangeHistory);
			}else{
				PicChangeHistory picChangeHistory = new PicChangeHistory();
				picChangeHistory.setLicensePlate(accept.getLicensePlate());
				picChangeHistory.setInsertUserId(accept.getInsertUserid());
				picChangeHistory.setOperateFlag(2);
				picChangeHistory.setRemark("车辆处于过户中，车辆重新查验失败.");
				picChangeHistory.setSuccessFlag(2);
				picChangeHistory.insertPicChange(picChangeHistory);
				flags = "2";
			}
			}
			controller.commit();
			return flags;
		} catch (Exception e) {
			logger.error("error:", e);
			try {
				controller.rollback();
			} catch (TransactionException e1) {}
		}
		return flags;
	}

	/**
	 * 交易车辆查验车辆基本信息、图片数据同步下载
	 * 
	 * @param serial
	 * @param licenseplate
	 * @return
	 */
	public static TransferAcceptedInfo loadCarInfo(String serial,
			String licenseplate) {
		logger.info(" 交易车辆查验车辆基本信息、图片数据获取开始...");
		// 直接在过户表中查询过户信息
		TransferAcceptedInfo accept = new TransferAcceptedInfo();
		try {
			accept = accept.searchAcceptInfoToPad(serial, licenseplate);
		} catch (TmsDaoException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		logger.info(" 交易车辆查验车辆基本信息、图片数据获取结束...");
		return accept;
	}

	/**
	 * 库存查验会员信息同步
	 * 
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public static List loadMember() {
		logger.info("调取经济公司开始...");
		TxController controller = TxController.getTxController();
		try {
			controller.begin();
			Member member = Member.getInstance();
			// 传递原始信息
			List list = member.findAllMemInfo();
			if (list.size() < 1) {
				logger.info("未取到会员信息...");
				controller.commit();
				return null;
			}
			controller.commit();
			logger.info("调取经济公司结束...");
			return list;
		} catch (TransactionException e) {
			e.printStackTrace();
		} catch (TmsDaoException e) {
			e.printStackTrace();
		}
		return null;
	}

	/**
	 * 图片转化成字符串
	 * 
	 * @param args
	 * @throws IOException
	 */
	public static String transPicToStr(String serial, String imgFile) {// 将图片文件转化为字节数组字符串，并对其进行Base64编码处理
		// String imgFile = "d:\\111.jpg";// 待处理的图片
		File f = new File(ImageUtils.getImageDirectoryPath(Registry.getConfig(TmsConstants.WWW_CHECKPAD_IMAGE_UPLOAD_PUT_KEY) + "/" + serial+ "/" + imgFile));
		InputStream in = null;
		byte[] data = null;
		// 读取图片字节数组
		try {
			in = new FileInputStream(f);
			data = new byte[in.available()];
			in.read(data);
			in.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
		// 对字节数组Base64编码
		BASE64Encoder encoder = new BASE64Encoder();
		return encoder.encode(data);// 返回Base64编码过的字节数组字符串
	}

	/**
	 * 将字符串转为图片
	 * 
	 * @param imgStr
	 * @return
	 */
	public static boolean generateImage(String imgStr, String imgFile)
			throws Exception {// 对字节数组字符串进行Base64解码并生成图片
		if (imgStr == null) // 图像数据为空
			return false;
		BASE64Decoder decoder = new BASE64Decoder();
		try {
			// Base64解码
			byte[] b = decoder.decodeBuffer(imgStr);
			for (int i = 0; i < b.length; ++i) {
				if (b[i] < 0) {// 调整异常数据
					b[i] += 256;
				}
			}
			// 生成jpeg图片
			String imgFilePath = imgFile;// 新生成的图片
			OutputStream out = new FileOutputStream(imgFilePath);
			out.write(b);
			out.flush();
			out.close();
			return true;
		} catch (Exception e) {
			throw e;
		}
	}

	/**
	 * 图片上传处理工具
	 * registry.car.weservice.carPic WEB_SERVICE_PIC WWW_CHECKPAD_IMAGE_UPLOAD
	 * www.upload.ContextRoot UPLOAD_CONTEXT_ROOT WWW_CHECKPAD_IMAGE_UPLOAD_PUT
	 * @param serial
	 * @param key
	 * @param imgStr
	 * @return
	 */
	private static String imageTool(String serial, String key, String imgStr,String scImagePath,String dbImagePath) {
		 String fileName = ImageUtils.getImageUrl(dbImagePath + "/" + serial + "/" + serial + "_" + key + ".jpg");
		// 图片名称
		File file = new File(ImageUtils.getImageDirectoryPath(scImagePath + "/" + serial + "/"));
		boolean bsflag;
		try {
			bsflag = generateImage(imgStr, file + "/" + serial + "_" + key + ".jpg");
			if (bsflag == false) {
				logger.info("图片" + key + "为空!");
				return "";
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return fileName;
	}
	

	// public static void main(String[] args) throws IOException {
	//		 
	// // System.out.println(getImageStr("c:\\asdadad.jpg"));
	//		 
	// // 将图片转换成字符串
	// // File f = new File("c:\\asdadad.jpg");
	// // FileInputStream fis = new FileInputStream( f );
	// // byte[] bytes = new byte[fis.available()];
	// // fis.read(bytes); fis.close();
	// //
	// // String imgStr = byte2hex( bytes );
	// // System.out.println( imgStr);
	// }

}
